package com.nuoniu.sibanyun.service.erp.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.nuoniu.sibanyun.entity.erp.ErpProjectDeliverable;
import com.nuoniu.sibanyun.mapper.erp.ErpProjectDeliverableMapper;
import com.nuoniu.sibanyun.service.erp.IErpProjectDeliverableService;
import com.nuoniu.sibanyun.userThread.UserInfo;
import com.nuoniu.sibanyun.userThread.UserThreadLocal;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * <p>
 * 交付物 服务实现类
 * </p>
 *
 * @author 小啊刚
 * @since 2021-10-26
 */
@Service
public class ErpProjectDeliverableServiceImpl extends ServiceImpl<ErpProjectDeliverableMapper, ErpProjectDeliverable> implements IErpProjectDeliverableService {

    @Override
    public List<ErpProjectDeliverable> getList(Integer projectId) {
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("project_id", projectId);
        return list(wrapper);
    }

    @Override
    public void saveDeliverable(ErpProjectDeliverable deliverable) {
        if(deliverable.getId() == null) {
            UserInfo userInfo = UserThreadLocal.get();
            deliverable.setCreateUserId(userInfo.getUserId());
            deliverable.setCreateUserName(userInfo.getRealName());
            deliverable.setCreateDate(LocalDateTime.now());
        }

        saveOrUpdate(deliverable);
    }
}
